<!DOCTYPE HTML>
<html lang="en" >
    
    <head>
        
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>补码 | python 数据结构与算法</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-search/search.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../剑指offer/剑指offer1-24题.html" />
    
    
    <link rel="prev" href="../index.html" />
    

        
    </head>
    <body>
        
        
    <div class="book"
        data-level="1.1"
        data-chapter-title="补码"
        data-filepath="剑指offer/补码.md"
        data-basepath=".."
        data-revision="Mon Jun 10 2019 17:10:15 GMT+0800 (中国标准时间)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        python数据结构与算法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" >
            
            <span><b>1.</b> 剑指offer</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.1" data-path="剑指offer/补码.html">
            
                
                    <a href="../剑指offer/补码.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        补码
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="剑指offer/剑指offer1-24题.html">
            
                
                    <a href="../剑指offer/剑指offer1-24题.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        剑指offer1-24题
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="剑指offer/剑指offer25-43题.html">
            
                
                    <a href="../剑指offer/剑指offer25-43题.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        剑指offer25-43题
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="树的实现/树的定义.html">
            
                
                    <a href="../树的实现/树的定义.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        各种树
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="树的实现/B-树.html">
            
                
                    <a href="../树的实现/B-树.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        B-树
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="树的实现/B+树.html">
            
                
                    <a href="../树的实现/B+树.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        B+树
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="树的实现/红黑树.html">
            
                
                    <a href="../树的实现/红黑树.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        红黑树
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" >
            
            <span><b>3.</b> 六大排序</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="六大排序/六大基本排序.html">
            
                
                    <a href="../六大排序/六大基本排序.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        六大基本排序
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="六大排序/快速排序.html">
            
                
                    <a href="../六大排序/快速排序.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        快速排序
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="4" >
            
            <span><b>4.</b> 算法的介绍</span>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1" data-path="算法的介绍/字典序算法.html">
            
                
                    <a href="../算法的介绍/字典序算法.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.1.</b>
                        
                        字典序算法
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="4.2" data-path="算法的介绍/布隆算法.html">
            
                
                    <a href="../算法的介绍/布隆算法.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>4.2.</b>
                        
                        布隆算法
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    Published with GitBook
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >python 数据结构与算法</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h4 id="&#x8865;&#x7801;">&#x8865;&#x7801;</h4>
<p>&#x7279;&#x6027;&#xFF1A;</p>
<p>1&#x3001;&#x4E00;&#x4E2A;&#x8D1F;&#x6574;&#x6570;&#xFF08;&#x6216;&#x539F;&#x7801;&#xFF09;&#x4E0E;&#x5176;&#x8865;&#x6570;&#xFF08;&#x6216;&#x8865;&#x7801;&#xFF09;&#x76F8;&#x52A0;&#xFF0C;&#x548C;&#x4E3A;&#x6A21;&#x3002;</p>
<p>2&#x3001;&#x5BF9;&#x4E00;&#x4E2A;&#x6574;&#x6570;&#x7684;&#x8865;&#x7801;&#x518D;&#x6C42;&#x8865;&#x7801;&#xFF0C;&#x7B49;&#x4E8E;&#x8BE5;&#x6574;&#x6570;&#x81EA;&#x8EAB;&#x3002;</p>
<p>3&#x3001;&#x8865;&#x7801;&#x7684;&#x6B63;&#x96F6;&#x4E0E;&#x8D1F;&#x96F6;&#x8868;&#x793A;&#x65B9;&#x6CD5;&#x76F8;&#x540C;</p>
<h4 id="&#x6309;&#x4F4D;&#x53D6;&#x53CD;-">&#x6309;&#x4F4D;&#x53D6;&#x53CD; ~</h4>
<p>~&#xFF0C;&#x7528;&#x6CD5;&#x53EA;&#x6709;&#x4E00;&#x4E2A;&#x90A3;&#x5C31;&#x662F;&#x6309;&#x4F4D;&#x53D6;&#x53CD;&#xFF0C;&#x9700;&#x8981;&#x6CE8;&#x610F;&#x7684;&#x662F;&#xFF1A;</p>
<ul>
<li>~&#x7684;&#x6309;&#x4F4D;&#x53D6;&#x53CD;&#xFF0C;&#x5305;&#x62EC;&#x7B26;&#x53F7;&#x4F4D;</li>
<li>&#x6B63;&#x6570;&#x5404;&#x4F4D;&#x53D6;&#x53CD;&#x53D8;&#x4E3A;&#x8D1F;&#x6570;&#xFF0C;&#x663E;&#x793A;&#x65F6;&#x8F6C;&#x5316;&#x4E3A;&#x5176;&#x8865;&#x7801;</li>
<li>&#x8D1F;&#x6570;&#x672C;&#x8EAB;&#x9700;&#x8981;&#x5148;&#x8F6C;&#x6362;&#x4E3A;&#x8865;&#x7801;&#xFF08;&#x7B26;&#x53F7;&#x4F4D;&#x4E0D;&#x53D8;&#xFF0C;&#x5404;&#x4F4D;&#x53D6;&#x53CD;&#x518D;&#x52A0; 1&#xFF09;&#xFF0C;&#x518D;&#x5BF9;&#x5176;&#x8865;&#x7801;&#x8FDB;&#x884C;&#x5404;&#x4F4D;&#x53BB;&#x53CD;</li>
</ul>
<h5 id="1-5">1. ~5</h5>
<p>5 &#x7684;&#x4E8C;&#x8FDB;&#x5236;&#x4E3A; 0101&#xFF0C;</p>
<p>~5</p>
<ul>
<li>&#xFF08;1&#xFF09;&#x5404;&#x4F4D;&#x53D6;&#x53CD;&#xFF0C;1010</li>
<li>&#xFF08;2&#xFF09;&#x53D8;&#x4E3A;&#x8D1F;&#x6570;&#xFF0C;&#x8F6C;&#x5316;&#x4E3A;&#x5176;&#x8865;&#x7801;&#x5F62;&#x5F0F;&#xFF08;&#x7B26;&#x53F7;&#x4F4D;&#x4FDD;&#x6301;&#x4E0D;&#x53D8;&#xFF09;&#xFF0C;&#x5404;&#x4F4D;&#x53D6;&#x53CD; 1&#xFF08;1101&#xFF09;&#xFF0C;&#x518D;&#x52A0;1&#xFF08;1110&#xFF09;&#xFF0C;&#x4E5F;&#x5373; -6</li>
</ul>
<pre><code class="lang-python">&gt;&gt; ~<span class="hljs-number">5</span>
&gt;&gt; -<span class="hljs-number">6</span>
</code></pre>
<h5 id="2-5">2. ~(-5)</h5>
<p>-5 &#x56E0;&#x4E3A;&#x662F;&#x8D1F;&#x6570;&#xFF0C;&#x5B58;&#x50A8;&#x65F6;&#x5B58;&#x50A8;&#x7684;&#x662F;&#x5176;&#x8865;&#x7801;&#xFF1A;</p>
<ul>
<li>-5 &#x7684;&#x8865;&#x7801;&#x662F;&#xFF1A;1011&#xFF0C;</li>
<li>~(-5)&#x5C06;&#x5176;&#x5404;&#x4F4D;&#x53D6;&#x53CD;&#xFF08;&#x5305;&#x62EC;&#x7B26;&#x53F7;&#x4F4D;&#xFF09;&#xFF0C;&#x4E5F;&#x5373; 0100&#xFF08;4&#xFF09;</li>
</ul>
<pre><code class="lang-python">&gt;&gt; ~(-<span class="hljs-number">5</span>)
&gt;&gt; <span class="hljs-number">4</span>
</code></pre>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../index.html" class="navigation navigation-prev " aria-label="Previous page: python数据结构与算法"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../剑指offer/剑指offer1-24题.html" class="navigation navigation-next " aria-label="Next page: 剑指offer1-24题"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-search/lunr.min.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-search/search.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"highlight":{},"search":{"maxIndexSize":1000000},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2}};
    gitbook.start(config);
});
</script>

        
    </body>
    
</html>
